package exercises.Charpter8;

//: polymorphism/Transmogrify.java
// Dynamically changing the behavior of an object
// via composition (the "State" design pattern).
import static net.mindview.util.Print.*;

class Actor {
  public void act() {}
}

class HappyActor extends Actor {
  public void act() { print("HappyActor"); }
}

class SadActor extends Actor {
  public void act() { print("SadActor"); }
}

class Stage {
  private Actor actor = new HappyActor();
  public void change() { actor = new SadActor(); }
  public void performPlay() { actor.act(); }
}

class AlertStatus{
	int status = 0;
	public String getStatus() {
		switch (status) {
		case 0:	return "Nothing";
		case 1:	return "Warning";
		case 2:	return "Alert";
		default:
			break;
		}
		return null;
	}
	public void setStatus(int status) {
		if ((status < 3)&&(status >= 0))
			this.status = status;
	}
}

class Starship{
	private AlertStatus alert = new AlertStatus();
	@Override
	public String toString() {
		return getAlert().getStatus();
	}
	private AlertStatus getAlert() {
		return alert;
	}
	public void setAlert(int status) {
		this.alert.setStatus(status);
	}
	
}

public class Sixteen {
  public static void main(String[] args) {
    Starship a = new Starship();
    a.setAlert(2);
    System.out.println(a);
    a.setAlert(1);
    System.out.println(a);
    a.setAlert(0);
    System.out.println(a);
  }
} /* Output:
HappyActor
SadActor
*///:~
